﻿using ApplicationBase.Core.Attributes;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Authorization.Policy;

namespace IdentityService.WebAPI.Middlewares
{
    public class AppAuthorizationMiddlewareResultHandler : IAuthorizationMiddlewareResultHandler
    {
        private readonly AuthorizationMiddlewareResultHandler defaultHandler = new();

        public async Task HandleAsync(RequestDelegate next, HttpContext context, AuthorizationPolicy policy, PolicyAuthorizationResult authorizeResult)
        {
            //var endpoint = context.GetEndpoint();
            //if (endpoint != null) 
            //{
            //    var needPermit = endpoint.Metadata.GetMetadata<PermitAttribute>();
            //    if (needPermit != null)
            //    {
            //        Console.WriteLine(needPermit.Name);
            //    }
            //}

            await defaultHandler.HandleAsync(next, context, policy, authorizeResult);
        }
    }
}
